~ chicken-core (master) /manual/Extensions to the standard
Trap1[[tags: manual]]23[[toc:]]45== Extensions to the R7RS standard67=== Brackets and braces89The brackets {{[ ... ]}} and the braces {{ { ... } }} are10provided as an alternative syntax for {{( ... )}}. A number of reader11extensions is provided.1213=== User defined character names1415User defined character names are supported. See16{{char-name}}. Numeric hexadecimal character codes above are supported and can be read17using ''#\uXXXX'' and ''#\UXXXXXXXX'', in addition to the standard ''\x...;'' notation.1819Non-standard characters names supported are {{#\linefeed}}, {{#\vtab}}, {{#\nul}}, {{#\page}} and {{#\esc}}.2021== Non-standard read syntax2223=== Multiline Block Comment2425<read>#|</read>2627 #| ... |#2829A multiline ''block'' comment. May be nested. Implements [[http://srfi.schemers.org/srfi-30/srfi-30.html|SRFI-30]].3031=== Expression Comment3233<read>#;</read>3435 #;EXPRESSION3637Treats {{EXPRESSION}} as a comment. That is, the comment runs through the whole S-expression, regardless of newlines, which saves you from having to comment out every line, or add a newline in the middle of your parens to make the commenting of the last line work, or other things like that. Implements [[http://srfi.schemers.org/srfi-62/srfi-62.html|SRFI-62]].3839=== External Representation4041<read>#,</read>4243 #,(CONSTRUCTORNAME DATUM ...)4445Allows user-defined extension of external representations. (For more information see the documentation for46[[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]])4748=== Location Expression4950<read> #$EXPRESSION</read>5152An abbreviation for {{(location EXPRESSION)}}.5354=== Bytevector strings5556<read>#u8"..."</read>5758String syntax for bytevectors, as an alternative to {{#u8(...)}}. The usual escape sequences for strings are recognized.5960<read>#u8{HEX...}</read>6162Hexadecimal bytevector syntax. {{HEX...}} should be an even number of hexadecimal characters representing63the contents of the vector.6465 #u8{deadbeef} == #u8(#xde #xad #xbe #xef}6667=== Keyword6869<read>#:</read>7071 #:SYMBOL72 SYMBOL:73 :SYMBOL7475Syntax for keywords. Keywords are symbol-like objects that evaluate to themselves, and as such don't have to be quoted. Either {{SYMBOL:}} or {{:SYMBOL}} is accepted, depending on the setting of the {{keyword-style}} parameter, but never both. {{#:SYMBOL}} is always accepted.7677=== Multiline String Constant7879<read>#<<</read>8081 #<<TAG8283Specifies a multiline string constant. Anything up to a line equal to {{TAG}} (or end of file) will be returned as a single string:8485 (define msg #<<END86 "Hello, world!", she said.87 END88 )8990is equivalent to9192 (define msg "\"Hello, world!\", she said.")9394=== Multiline String Constant with Embedded Expressions9596<read>#<#</read>9798 #<#TAG99100Similar to {{#<<}}, but allows substitution of embedded Scheme expressions prefixed with {{#}} and optionally enclosed in curly brackets. Two consecutive {{#}}s are translated to a single {{#}}:101102 (define three 3)103 (display #<#EOF104 This is a simple string with an embedded `##' character105 and substituted expressions: (+ three 99) ==> #(+ three 99)106 (three is "#{three}")107 EOF108 )109110prints111112 This is a simple string with an embedded `#' character113 and substituted expressions: (+ three 99) ==> 102114 (three is "3")115116=== Foreign Declare117118<read>#></read>119120 #> ... <#121122Abbreviation for {{(foreign-declare " ... ")}}.123124=== String escape sequences125126String-literals may contain the following escape sequences:127128<table style="margin-top: 1em; max-width: 40em">129<tr><th>Escape sequence</th><th>Character</th></tr>130<tr><td>{{\n}}</td><td>line feed / newline</td></tr>131<tr><td>{{\t}}</td><td>tab</td></tr>132<tr><td>{{\r}}</td><td>carriage return</td></tr>133<tr><td>{{\b}}</td><td>backspace</td></tr>134<tr><td>{{\a}}</td><td>bell</td></tr>135<tr><td>{{\v}}</td><td>vertical tab</td></tr>136<tr><td>{{\f}}</td><td>form feed</td></tr>137<tr><td>{{\x}}''XX;''</td><td>hexadecimal 8-bit character code</td></tr>138<tr><td>{{\u}}''XXXX''</td><td>hexadecimal 16-bit Unicode character code</td></tr>139<tr><td>{{\U}}''XXXXXXXX''</td><td>hexadecimal 32-bit Unicode character code</td></tr>140<tr><td>{{\}}''OOO''</td><td>octal 8-bit character code</td></tr>141<tr><td>{{\|}} {{\"}} {{\\}} {{\'}}</td><td>the escaped character</td></tr>142</table>143144145=== Bang146147<read>#!</read>148149 #!...150151Interpretation depends on the directly following characters. Only the following are recognized. Any other case results in a read error.152153; Line Comment : If followed by whitespace or a slash, then everything up the end of the current line is ignored154155; Eof Object : If followed by the character sequence {{eof}}, then the (self-evaluating) end-of-file object is returned156157; DSSSL Formal Parameter List Annotation : If followed by any of the character sequences {{optional}}, {{rest}} or {{key}}, then a symbol with the same name (and prefixed with {{#!}}) is returned158159; Read Mark Invocation : If a ''read mark'' with the same name as the token is registered, then its procedure is called and the result of the read-mark procedure will be returned (see {{set-read-syntax!}}).160161=== Conditional Expansion162163<read>#+</read>164165 #+FEATURE EXPR166167Rewrites to168169 (cond-expand (FEATURE EXPR) (else))170171and performs the feature test at macroexpansion time. Therefore, it may not172work as expected when used within a macro form.173174---175Previous: [[Deviations from the standard]]176177Next: [[Interface to external functions and variables]]